


#include <stdlib.h>
#include <iostream>
#include "door.h"



using namespace std;


void Door::putText( ostream &S ) const
{
    S << '#' << int( getNumber() ) << ';' <<
        getColor().getText() << ';' <<
        ( tellsTruth() ?  "1;" : "0;" ) <<
        ( isSafe() ? "1;" : "0;" ) <<
        ( hasSign() ? '1' : '0' ) << endl;
}



// Door ::



Door::Door( uint8_t num, bool safe, bool truth, Color::eColor col ) :
    Subject( truth, col ),
    m_nNumber( num ),
    m_bSafe( safe ),
    m_bPendingSafe( safe ),
    m_bHasSign( true )
{
}



/// the door can mutate
bool Door::mutate()
{
    if( Subject::mutate() )
    {
        m_bPendingSafe = !m_bPendingSafe;
        if( m_bPendingSafe == m_bSafe )
            return true;
    }
    return false;
}



void Door::restore()
{
    Subject::restore();
    m_bPendingSafe = m_bSafe;
} 



bool Door::isLikeInitial() const
{
    return m_bPendingSafe == m_bSafe;
}
